<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>数据上报计划</title>
    <#include "/common/resource.ftl">
    <script type="text/javascript" src="${params.contextPath}/js/moment.min.js"></script>
    <script type="text/javascript">
        var getSearchParams = function(){
            return {
            	name:$("input[name='name']").val() || "",
            };
        }
    </script>
</head>
<body class="bg-gray">

   <div class="ui-operation">
       <div class="ui-buttons">
   		 <div class="layui-btn-group tools">
            <button class="layui-btn layui-btn-normal open-dialog" p="url:'${params.contextPath}/view/icip/datareport/datareport_plan_edit.htm',title:'添加数据上报计划',width:'800px',height:'90%'">
				<i class="fa fa-plus"></i>添加
			</button>
			<!-- <button class="layui-btn layui-btn-normal singleSelected" p="url:'${params.contextPath}/view/icip/datareport/datareport_plan_edit.htm',title:'编辑数据上报计划',width:'800px',height:'90%'">
				<i class="fa fa-pencil"></i>修改
			</button> -->
			<button class="layui-btn layui-btn-normal remove-button" reurl="${params.contextPath}/web/taskCycle/delete.json">
				<i class="fa fa-remove"></i>删除
			</button>
			<button class="layui-btn layui-btn-normal  accept-button" reurl="${params.contextPath}/web/taskCycle/accept.json">
				<i class="fa fa-play"></i>启用
			</button>
			<button class="layui-btn layui-btn-normal  stop-button" reurl="${params.contextPath}/web/taskCycle/stop.json">
				<i class="fa fa-stop"></i>停用
			</button>
         </div>
         <div class="ui-searchs">
             <div class="value" style="">
             
                 <input type="text" name="name" placeholder="数据上报模板">
             </div>
             <input type="button" value="搜索" class="layui-btn layui-btn-danger search-button"/>
         </div>
       </div>
   </div>
   <div class="ui-content" style="padding-left: 10px;padding-right:10px;">
       <table id="datagrid" options="url:'${params.contextPath}/web/taskCycle/list.json',params:'getSearchParams',dblClickRow:'showDetail'">
			<thead>
               	<tr>
               		<th data-options="field:'ck',checkbox:true"></th>
                   <th data-options="field:'typeStr',width:80">计划类型</th>
                   <th data-options="field:'priorityStr',width:120,formatter:formatPriority">优先级</th>
                   <th data-options="field:'templateName',width:120">数据上报模板</th>
                   <th data-options="field:'intervalDate',width:100,formatter:formatPeriod">任务发布周期</th>
                   <th data-options="field:'startLineStr',width:100">计划开始日期</th>
                   <th data-options="field:'deadLineStr',width:100">计划截止日期</th>
                   <!-- <th data-options="field:'complateTimeCount',width:100">要求完成时限</th> -->
                   <th data-options="field:'createName',width:80">编制人</th>
                   <th data-options="field:'orgName',width:100">编制单位</th>
                   <th data-options="field:'createTimeStr',width:120">编制时间</th>
                   <th data-options="field:'stateStr',width:40,formatter:formatState">状态</th>
				</tr>
			</thead>
       </table>
   </div>
   
</body>
<script type="text/javascript">
function formatPriority(val, row) {
    if (row.priority == 1) {
        return '<span class="ui-accept">' + val + '</span>';
    } else if(row.priority == 2){
        return '<span class="ui-warn">' + val + '</span>';
    }else if(row.priority == 3){
    	return '<span class="ui-stop">' + val + '</span>';
    }
    return val;
}
function formatState(val, row){
    if (row.state == 1) {
        return '<span class="ui-accept">' + val + '</span>';
    } else if(row.state == 2){
    	return '<span class="ui-stop">' + val + '</span>';
    }
    return val;
}
$(function(){
	
	$(".remove-button").click(function() {
		var ids = DataGrid.getCheckedIds();
		if (ids == "") {
			layer.msg("请选择删除记录")
			return false;
		}
		var url = $(this).attr("reurl");
		layer.confirm('确定删除记录', function() {
			$.ajaxRequest({
				url : url,
				data : {
					ids : ids.join(",")
				},
				success : function(data) {
					$.message(data.message);
					if (data.success) {
						DataGrid.reload();
					}
				}
			});
		});
	});
	
	$(".accept-button").click(function() {
		var ids = DataGrid.getCheckedIds();
		if (ids == "") {
			layer.msg("请选择启用计划")
			return false;
		}
		var url = $(this).attr("reurl");
		$.ajaxRequest({
			url : url,
			data : {
				ids : ids.join(",")
			},
			success : function(data) {
				$.message(data.message);
				if (data.success) {
					DataGrid.reload();
				}
			}
		});
	});
	
	$(".stop-button").click(function(){
		var ids = DataGrid.getCheckedIds();
		if (ids == "") {
			layer.msg("请选择停用计划")
			return false;
		}
		var url = $(this).attr("reurl");
		$.ajaxRequest({
			url : url,
			data : {
				ids : ids.join(",")
			},
			success : function(data) {
				$.message(data.message);
				if (data.success) {
					DataGrid.reload();
				}
			}
		});
	});
    
});
function showDetail (index, row) {
    var url = "${params.contextPath}/view/icip/datareport/datareport_plan_detail.htm?id=" + row.id;
    DialogManager.openDialog("url:'" + url + "',title:'计划任务详情',width:'800px',height:'450px'");
};

function formatPeriod(val,row){
	var weeks=['一','二','三','四','五','六','日'];
	
	if(row.type==0){
		return "立即发布";
	}else if(val){
		if(row.type==1){
			return row.typeStr+"发布";
		}
		if(row.type==2){
			return row.typeStr+weeks[val-1]+"发布";
		}
		if(row.type==3){
			return row.typeStr+val+"号"+"发布";
		}
	}else if(val==0){
		return row.typeStr+"发布";
	}
	return "";
}

function formatDeadLine(val, row){
	if(row.type==0){
		return "";
	}else if(val){
		var d = new Date(val);
		return moment(d).format("YYYY-MM-DD");
	}
}


function formatCreateTime(val, row){
	if(val){
		var d = new Date(val);
		return moment(d).format("YYYY-MM-DD HH:mm:ss");
	}
}
</script>
</html>
